/*
 * Copyright (c) 2006-2019, RT-Thread Development Team
 *
 * SPDX-License-Identifier: Apache-2.0
 *
 * Change Logs:
 * Date           Author       Notes
 * 2020-02-16     akqbd       the first version
 */
#include <rtthread.h>
#include <board.h>
#include <finsh.h>
#include <rtdbg.h>
#include <rtdevice.h>
#include  "byte_queue/byte_queue.h"
#include "enhanced_byte_queue/enhanced_byte_queue.h"

#ifndef QUEUE_BUFFER_SIZE
#   define QUEUE_BUFFER_SIZE       256
#endif
static enhanced_byte_queue_t s_tQueue;

void plooc_test(void)
{
    rt_kprintf("Hello PLOOC!\r\n\r\n");
    do {
        static uint8_t s_chQueueBuffer[QUEUE_BUFFER_SIZE];
        const enhanced_byte_queue_cfg_t tCFG = {
            s_chQueueBuffer,
            sizeof(s_chQueueBuffer),
        };

        ENHANCED_BYTE_QUEUE.Init(&s_tQueue, (enhanced_byte_queue_cfg_t *)&tCFG);
    } while(0);

    //! you can enqueue
    ENHANCED_BYTE_QUEUE.Enqueue(&s_tQueue, 'p');
    ENHANCED_BYTE_QUEUE.Enqueue(&s_tQueue, 'L');
    ENHANCED_BYTE_QUEUE.Enqueue(&s_tQueue, 'O');
    ENHANCED_BYTE_QUEUE.Enqueue(&s_tQueue, 'O');
    ENHANCED_BYTE_QUEUE.Enqueue(&s_tQueue, 'C');

    ENHANCED_BYTE_QUEUE.use_as__i_byte_queue_t.Enqueue(&s_tQueue.use_as__byte_queue_t, '.');
    ENHANCED_BYTE_QUEUE.use_as__i_byte_queue_t.Enqueue(&s_tQueue.use_as__byte_queue_t, '.');
    ENHANCED_BYTE_QUEUE.use_as__i_byte_queue_t.Enqueue(&s_tQueue.use_as__byte_queue_t, '.');

    //! you can dequeue
    do {
        uint_fast16_t n = ENHANCED_BYTE_QUEUE.Count(&s_tQueue);
        uint8_t chByte;
        rt_kprintf("There are %d byte in the queue!\r\n", n);
        rt_kprintf("let's peek!\r\n");

        while(ENHANCED_BYTE_QUEUE.Peek.PeekByte(&s_tQueue, &chByte)) {
            rt_kprintf("%c\r\n", chByte);
        }
        rt_kprintf("There are %d byte(s) in the queue!\r\n",
                ENHANCED_BYTE_QUEUE.Count(&s_tQueue));
        rt_kprintf("Let's remove all peeked byte(s) from queue... \r\n");
        ENHANCED_BYTE_QUEUE.Peek.GetAllPeeked(&s_tQueue);
        rt_kprintf("Now there are %d byte(s) in the queue!\r\n",
                ENHANCED_BYTE_QUEUE.Count(&s_tQueue));
    } while(0);

}
MSH_CMD_EXPORT(plooc_test, plooc_test);
